package com.crm.jdy.controller.usermanager;

import com.crm.jdy.common.pojo.RolePermiss;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.usermanager.RolePermissService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
* <p>说明： 用户角色关联权限API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年3月30日
*/
@Api(tags = "rolePermiss", description ="用户角色关联权限")
@RestController
@RequestMapping("/rolePermiss")
public class RolePermissController{

    @Reference(version = "${service.version}", check = false)
    RolePermissService rolePermissService;

    @RateLimit()
    @ApiOperation("角色关联的权限批量加入")
    @PostMapping("/insertAllRolePermiss")
    public ResultVo insertAllRolePermiss(@Validated @RequestBody List<RolePermiss> permissList){
         boolean b = rolePermissService.insertAllRolePermiss(permissList);
         if(b){
             return  ResultVo.success("添加成功");
         }
        return  ResultVo.failed("添加失败");
    }

    @RateLimit()
    @ApiOperation("角色管理信息")
    @PostMapping("/seleteRolePermiss")
    public ResultVo seleteRolePermiss(@RequestBody RolePermiss callAplanInfoDto){
        List<RolePermiss> list = rolePermissService.seleteRolePermiss(callAplanInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新角色管理")
    @PostMapping("/updateRolePermiss")
    public ResultVo updateRolePermiss(@ApiParam(value = "roleInfo", required = true)
                                      @Validated @RequestBody RolePermiss roleInfo){
        boolean index = rolePermissService.updateRolePermiss(roleInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加角色管理")
    @PostMapping("/addRolePermiss")
    public ResultVo addRolePermiss(@ApiParam(name = "roleInfo", required = false)
                                   @Validated @RequestBody RolePermiss roleInfo){
        boolean list  = rolePermissService.addRolePermiss(roleInfo);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("删除角色管理")
    @DeleteMapping("deleteRolePermiss/{rpid}")
    public ResultVo deleteRolePermiss(@NotNull @ApiParam(name = "rpid", value = "rpid", required = true) @PathVariable String rpid){
        boolean b = rolePermissService.removeRolePermiss(rpid);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }





}